
package projetomsn.Client.UI.FontConfig;

import java.sql.SQLException;
import java.util.logging.Level;
import projetomsn.Client.Settings.SettingsFile;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Robot;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *Classe para configuração de fonte, tela de configuração
 */
public class FontStyleFrame extends javax.swing.JFrame {

    /** 
     * Altera a fonte do nome do usuário 
     */
    private FontHTML myNameFont;
    /**
     * Altera a fonte do separador, nome do usuário com
     * a mensagem a ser enviada, do usuário
     */
    private FontHTML mySeparatorFont;
    /**
     * Altera fonte da mensagem a ser enviada pelo usuário
     */
    private FontHTML myTextFont;
    /**
     * Altera a fonte do nome do amigo
     */
    private FontHTML friendNameFont;
    /**
     * Altera a fonte do separador, nome do amigo com
     * a mensagem enviada, do amigo
     */
    private FontHTML friendSeparatorFont;
    /**
     * Altera a fonte da mensagem enviada pelo amigo
     */
    private FontHTML friendTextFont;
    /**
     * Nome do arquivo onde a configuração do texto será salvo
     */
    private String settingsFileName;
    /**
     * Tamanho da fonte
     */
    private int size = 0;
    /**
     * Variável de criação de log
     */
    private static Logger log = Logger.getLogger(FontStyleFrame.class.getName());
    /**
     * Cria internacionalização
     */
    
    private ResourceBundle myResources;
    //= ResourceBundle.getBundle("Properties.messages", Locale.getDefault());
    
    private String language;
    /**
     * Metodo construtor da classe FontStyleFrame
     * @param fileName 
     */
    public FontStyleFrame(String fileName) {

        Locale.getDefault();
        
        System.out.println(Locale.getDefault().toString());

        if(Locale.getDefault().toString().equalsIgnoreCase("pt_BR"))
            language = "Properties/messages_pt_BR";
        else if(Locale.getDefault().toString().equalsIgnoreCase("en_US"))
            language = "Properties/messages_en_US";

        myResources =
            ResourceBundle.getBundle(language , Locale.getDefault());

        initComponents();
        setVisible(true);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        myNameFont = new FontHTML();
        mySeparatorFont = new FontHTML();
        myTextFont = new FontHTML();

        friendNameFont = new FontHTML();
        friendSeparatorFont = new FontHTML();
        friendTextFont = new FontHTML();

        settingsFileName = fileName;

        displayFontStyleTextPane.setContentType("text/html");
        displayFontStyleTextPane.setDoubleBuffered(true);
        displaySetText();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        chooseFontLabel = new javax.swing.JLabel();
        fontComboBox = new javax.swing.JComboBox();
        styleLabel = new javax.swing.JLabel();
        boldButton = new javax.swing.JLabel();
        italicButton = new javax.swing.JLabel();
        underlineButton = new javax.swing.JLabel();
        fontSizeSpinner = new javax.swing.JSpinner();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        displayFontStyleTextPane = new javax.swing.JTextPane();
        chooseYourFontStyleLabel = new javax.swing.JLabel();
        editingCombobox = new javax.swing.JComboBox();
        colorPickerPanel = new javax.swing.JPanel();
        colorPickerLabel = new javax.swing.JLabel();
        saveChangesButton = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        optionMenu = new javax.swing.JMenu();
        settingsMenu = new javax.swing.JMenu();
        saveMySettingsMenuItem = new javax.swing.JMenuItem();
        saveMyDefaultSettingsMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(247, 216, 207));

        chooseFontLabel.setFont(new java.awt.Font("Trebuchet MS", 0, 18)); // NOI18N
        chooseFontLabel.setForeground(new java.awt.Color(102, 0, 0));
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Properties/messages"); // NOI18N
        chooseFontLabel.setText(bundle.getString("font.label.fontes")); // NOI18N

        fontComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Verdana", "Courier New", " ", " ", " " }));
        fontComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fontComboBoxActionPerformed(evt);
            }
        });

        styleLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/Font/style_1.png"))); // NOI18N

        boldButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/Font/text_bold.png"))); // NOI18N
        boldButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                boldButtonMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                boldButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                boldButtonMouseExited(evt);
            }
        });

        italicButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/Font/text_italic.png"))); // NOI18N
        italicButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                italicButtonMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                italicButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                italicButtonMouseExited(evt);
            }
        });

        underlineButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/Font/text_underline.png"))); // NOI18N
        underlineButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                underlineButtonMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                underlineButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                underlineButtonMouseExited(evt);
            }
        });

        fontSizeSpinner.setFont(new java.awt.Font("Tahoma", 2, 18));
        fontSizeSpinner.setModel(new javax.swing.SpinnerNumberModel(12, 1, 28, 4));
        fontSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                fontSizeSpinnerStateChanged(evt);
            }
        });

        jPanel2.setAutoscrolls(true);

        displayFontStyleTextPane.setEditable(false);
        jScrollPane1.setViewportView(displayFontStyleTextPane);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
        );

        chooseYourFontStyleLabel.setFont(new java.awt.Font("Trebuchet MS", 3, 14)); // NOI18N
        chooseYourFontStyleLabel.setText(bundle.getString("font.label.editar")); // NOI18N

        editingCombobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { myResources.getString("font.CB.meu.nome"), myResources.getString("font.CB.meu.separador"), myResources.getString("font.CB.meu.texto"), myResources.getString("font.CB.amigo.mome"), myResources.getString("font.CB.amigo.separador"), myResources.getString("font.CB.amigo.texto") }));
        editingCombobox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editingComboboxActionPerformed(evt);
            }
        });

        colorPickerLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/Font/color.jpg"))); // NOI18N
        colorPickerLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                colorPickerLabelMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                colorPickerLabelMouseReleased(evt);
            }
        });
        colorPickerLabel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                colorPickerLabelMouseDragged(evt);
            }
        });

        javax.swing.GroupLayout colorPickerPanelLayout = new javax.swing.GroupLayout(colorPickerPanel);
        colorPickerPanel.setLayout(colorPickerPanelLayout);
        colorPickerPanelLayout.setHorizontalGroup(
            colorPickerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(colorPickerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, Short.MAX_VALUE)
        );
        colorPickerPanelLayout.setVerticalGroup(
            colorPickerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(colorPickerLabel)
        );

        saveChangesButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        saveChangesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/botoes_icones/disk.png"))); // NOI18N
        saveChangesButton.setText(bundle.getString("font.button.salvar")); // NOI18N
        saveChangesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveChangesButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(chooseFontLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(fontComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(chooseYourFontStyleLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(editingCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(styleLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boldButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(italicButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(underlineButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fontSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(saveChangesButton)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(colorPickerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(styleLabel, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(chooseFontLabel)
                                    .addComponent(fontComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(editingCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(chooseYourFontStyleLabel)))
                            .addComponent(underlineButton)
                            .addComponent(fontSizeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(boldButton)
                            .addComponent(italicButton))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(colorPickerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(saveChangesButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        optionMenu.setText(bundle.getString("font.menu.opcoes")); // NOI18N

        settingsMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/botoes_icones/config0.png"))); // NOI18N
        settingsMenu.setText(bundle.getString("font.menuitem.configuracoes")); // NOI18N

        saveMySettingsMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetomsn/Client/pics/botoes_icones/disk.png"))); // NOI18N
        saveMySettingsMenuItem.setText(bundle.getString("font.menuitem.salvar")); // NOI18N
        settingsMenu.add(saveMySettingsMenuItem);

        saveMyDefaultSettingsMenuItem.setText(bundle.getString("font.menuitem.salvarbd")); // NOI18N
        settingsMenu.add(saveMyDefaultSettingsMenuItem);

        optionMenu.add(settingsMenu);

        jMenuBar1.add(optionMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Evento que altera o cursor quando o mouse passa sobre o botão de negrito
     * @param evt 
     */
    private void boldButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boldButtonMouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.HAND_CURSOR);
    }//GEN-LAST:event_boldButtonMouseEntered

    /**
     * Evento que altera o cursor quando o mouse não está mais sobre o botão
     * de negrito
     * @param evt 
     */
    private void boldButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boldButtonMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.DEFAULT_CURSOR);
    }//GEN-LAST:event_boldButtonMouseExited

    /**
     * Evento que altera o cursor quando o mouse passa sobre o botão de itálico
     * @param evt 
     */
    private void italicButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_italicButtonMouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.HAND_CURSOR);
    }//GEN-LAST:event_italicButtonMouseEntered

    /**
     * Evento que altera o cursor quando o mouse não está mais sobre o botão
     * de itálico
     * @param evt 
     */
    private void italicButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_italicButtonMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.DEFAULT_CURSOR);
    }//GEN-LAST:event_italicButtonMouseExited

    /**
     * Evento que altera o cursor quando o mouse passa sobre o botão de sublinhar
     * @param evt 
     */
    private void underlineButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_underlineButtonMouseEntered
        // TODO add your handling code here:
        setCursor(Cursor.HAND_CURSOR);
    }//GEN-LAST:event_underlineButtonMouseEntered

    /**
     * Evento que altera o cursor quando o mouse não está mais sobre o botão
     * de sublinhar
     * @param evt 
     */
    private void underlineButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_underlineButtonMouseExited
        // TODO add your handling code here:
        setCursor(Cursor.DEFAULT_CURSOR);
    }//GEN-LAST:event_underlineButtonMouseExited

    /**
     * Evento de alteração do tamanho do fonte do componente
     * @param evt 
     */
    private void fontSizeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fontSizeSpinnerStateChanged
        

        //convertendo o valor do spinner para o tamanho de fonte padrão HTML
        size = Integer.parseInt(fontSizeSpinner.getValue().toString()) / 4;

        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.size = size;
                break;
            case 1:
                mySeparatorFont.size = size;
                break;
            case 2:
                myTextFont.size = size;
                break;
            case 3:
                friendNameFont.size = size;
                break;
            case 4:
                friendSeparatorFont.size = size;
                break;
            case 5:
                friendTextFont.size = size;
                break;

        }
        displaySetText();
        
        

        
    }//GEN-LAST:event_fontSizeSpinnerStateChanged

    /**
     * Evento gerado ao clicar no botão de negrito
     * @param evt 
     */
    private void boldButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boldButtonMouseClicked
        


        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.BOLD = !myNameFont.BOLD;
                break;
            case 1:
                mySeparatorFont.BOLD = !mySeparatorFont.BOLD;
                break;
            case 2:
                myTextFont.BOLD = !myTextFont.BOLD;
                break;
            case 3:
                friendNameFont.BOLD = !friendNameFont.BOLD;
                break;
            case 4:
                friendSeparatorFont.BOLD = !friendSeparatorFont.BOLD;
                break;
            case 5:
                friendTextFont.BOLD = !friendTextFont.BOLD;
                break;

        }
        displaySetText();

        log.info(myResources.getString("font.log.negrito"));

    }//GEN-LAST:event_boldButtonMouseClicked

    /**
     * Evento gerado ao clicar no botão de itálico
     * @param evt 
     */
    private void italicButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_italicButtonMouseClicked
        // TODO add your handling code here:
        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.ITALIC = !myNameFont.ITALIC;
                break;
            case 1:
                mySeparatorFont.ITALIC = !mySeparatorFont.ITALIC;
                break;
            case 2:
                myTextFont.ITALIC = !myTextFont.ITALIC;
                break;
            case 3:
                friendNameFont.ITALIC = !friendNameFont.ITALIC;
                break;
            case 4:
                friendSeparatorFont.ITALIC = !friendSeparatorFont.ITALIC;
                break;
            case 5:
                friendTextFont.ITALIC = !friendTextFont.ITALIC;
                break;

        }
        displaySetText();

        log.info(myResources.getString("font.log.italico")+editingCombobox.getSelectedItem().toString());
    }//GEN-LAST:event_italicButtonMouseClicked

    /**
     * Evento gerado ao clicar no botçao de sublinhar
     * @param evt 
     */
    private void underlineButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_underlineButtonMouseClicked
        // TODO add your handling code here:
        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.UNDERLINE = !myNameFont.UNDERLINE;
                break;
            case 1:
                mySeparatorFont.UNDERLINE = !mySeparatorFont.UNDERLINE;
                break;
            case 2:
                myTextFont.UNDERLINE = !myTextFont.UNDERLINE;
                break;
            case 3:
                friendNameFont.UNDERLINE = !friendNameFont.UNDERLINE;
                break;
            case 4:
                friendSeparatorFont.UNDERLINE = !friendSeparatorFont.UNDERLINE;
                break;
            case 5:
                friendTextFont.UNDERLINE = !friendTextFont.UNDERLINE;
                break;

        }
        displaySetText();

        log.info(myResources.getString("font.log.sublinhado")+editingCombobox.getSelectedItem().toString());
    }//GEN-LAST:event_underlineButtonMouseClicked

    /**
     * Evento gerado ao selecionar o nome da fonte na Combobox
     * @param evt 
     */
    private void fontComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontComboBoxActionPerformed
        // TODO add your handling code here:
        String font = "null";
        switch (fontComboBox.getSelectedIndex()) {
            case 0:
                font = "Arial";
                break;
            case 1:
                font = "Verdana";
                break;
            case 2:
                font = "Courier New";
                break;
        }

        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.STYLE = font;
                break;
            case 1:
                mySeparatorFont.STYLE = font;
                break;
            case 2:
                myTextFont.STYLE = font;
                break;
            case 3:
                friendNameFont.STYLE = font;
                break;
            case 4:
                friendSeparatorFont.STYLE = font;
                break;
            case 5:
                friendTextFont.STYLE = font;
                break;

        }
        displaySetText();

        log.info(fontComboBox.getSelectedItem().toString() +
                myResources.getString("font.log.fonte.alterada") +
                editingCombobox.getSelectedItem().toString());
    }//GEN-LAST:event_fontComboBoxActionPerformed
    
    /**
     * Configura o fontSizeSpinner para o valor atual do texto 
     */
    private void editingComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editingComboboxActionPerformed
       

        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                //configura spinnerBox para o tamanho atual
                fontSizeSpinner.setValue(myNameFont.size);
                //confugura a fontCombobos para o tamanho atual
                fontComboBox.setSelectedIndex(getFontComboboxIndex(myNameFont.STYLE));
                break;
            case 1:
                //configura a spinnerBox para o tamanho atual
                fontSizeSpinner.setValue(mySeparatorFont.size);
                //configura a fontCombobox para o estilo atual
                fontComboBox.setSelectedIndex(getFontComboboxIndex(mySeparatorFont.STYLE));
                break;
            case 2:
                //configura o spinnerBox para o tamanho atual
                fontSizeSpinner.setValue(myTextFont.size);
                //configura a fontCombobox para o tamanho atual
                fontComboBox.setSelectedIndex(getFontComboboxIndex(myTextFont.STYLE));
                break;
            case 3:
                //configura o spinnerBox para o tamanho atual
                fontSizeSpinner.setValue(friendNameFont.size);
                //configura a fontCombobox para o tamanho atual
                fontComboBox.setSelectedIndex(getFontComboboxIndex(friendNameFont.STYLE));
                break;
            case 4:
                //configura o spinnerBox para o tamanho atual
                fontSizeSpinner.setValue(friendSeparatorFont.size);
                //configura a fontCombobox para o tamanho atual
                fontComboBox.setSelectedIndex(getFontComboboxIndex(friendSeparatorFont.STYLE));
                break;
            case 5:
                //configura o spinnerBox para o tamanho atual
                fontSizeSpinner.setValue(friendTextFont.size);
                //configura a fontCombobox para o estilo atual
                fontComboBox.setSelectedIndex(getFontComboboxIndex(friendTextFont.STYLE));
                break;
        }
    }//GEN-LAST:event_editingComboboxActionPerformed

    /**
     * Evento gerado pelo clique do mouse na tela de cores
     * @param evt 
     */
    private void colorPickerLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_colorPickerLabelMouseClicked
        // TODO add your handling code here:
        //cor escolhida no colorPicker
        String colorChosen = "";
        Robot robot;
        try {
            robot = new Robot();
            Color color = robot.getPixelColor(evt.getXOnScreen(), evt.getYOnScreen());
            //muda a cor para o caminho hexadecimal
            colorChosen = Integer.toHexString(color.getRed()) + ""
                    + Integer.toHexString(color.getGreen()) + ""
                    + Integer.toHexString(color.getBlue());
        } catch (AWTException ex) {
        }

        //troca parte do texto a ser mudada
        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.color = colorChosen;
                break;
            case 1:
                mySeparatorFont.color = colorChosen;
                break;
            case 2:
                myTextFont.color = colorChosen;
                break;
            case 3:
                friendNameFont.color = colorChosen;
                break;
            case 4:
                friendSeparatorFont.color = colorChosen;
                break;
            case 5:
                friendTextFont.color = colorChosen;
                break;

        }
        displaySetText();


    }//GEN-LAST:event_colorPickerLabelMouseClicked

    /**
     * Evento gerado ao arrastar o mouse sobre o gradiente de cores
     * @param evt 
     */
    private void colorPickerLabelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_colorPickerLabelMouseDragged
        // TODO add your handling code here:
        //cor escolhida no colorPicker
        String colorChosen = "";
        Robot robot;
        try {
            robot = new Robot();
            Color color = robot.getPixelColor(evt.getXOnScreen(), evt.getYOnScreen());
            //muda cor para caminho hexadecimal
            colorChosen = Integer.toHexString(color.getRed()) + ""
                    + Integer.toHexString(color.getGreen()) + ""
                    + Integer.toHexString(color.getBlue());
        } catch (AWTException ex) {
        }

        //troca parte do texto a ser mudada
        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.color = colorChosen;
                break;
            case 1:
                mySeparatorFont.color = colorChosen;
                break;
            case 2:
                myTextFont.color = colorChosen;
                break;
            case 3:
                friendNameFont.color = colorChosen;
                break;
            case 4:
                friendSeparatorFont.color = colorChosen;
                break;
            case 5:
                friendTextFont.color = colorChosen;
                break;

        }
        displaySetText();
    }//GEN-LAST:event_colorPickerLabelMouseDragged

    /**
     * Evento gerado ao liberar o botão do mouse no gradiente de cores
     * @param evt 
     */
    private void colorPickerLabelMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_colorPickerLabelMouseReleased
        // TODO add your handling code here:
        //cor escolhida no colorPicker
        String colorChosen = "";
        Robot robot;
        try {
            robot = new Robot();
            Color color = robot.getPixelColor(evt.getXOnScreen(), evt.getYOnScreen());
            //muda cor para caminho hexadecimal
            colorChosen = Integer.toHexString(color.getRed()) + ""
                    + Integer.toHexString(color.getGreen()) + ""
                    + Integer.toHexString(color.getBlue());
        } catch (AWTException ex) {
        }

        //troca parte do texto a ser mudada
        switch (editingCombobox.getSelectedIndex()) {
            case 0:
                myNameFont.color = colorChosen;
                break;
            case 1:
                mySeparatorFont.color = colorChosen;
                break;
            case 2:
                myTextFont.color = colorChosen;
                break;
            case 3:
                friendNameFont.color = colorChosen;
                break;
            case 4:
                friendSeparatorFont.color = colorChosen;
                break;
            case 5:
                friendTextFont.color = colorChosen;
                break;

        }
        displaySetText();
    }//GEN-LAST:event_colorPickerLabelMouseReleased

    /**
     * Evento gerado do botão que salva configurações
     * @param evt 
     */
    private void saveChangesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveChangesButtonActionPerformed
        // TODO add your handling code here:

       
        //conecta ao banco de dados
        SettingsFile.connect();
        try {
            //atualizando configurações de fonte
            SettingsFile.update("my_name", myNameFont.color, myNameFont.STYLE, myNameFont.size, myNameFont.BOLD, myNameFont.ITALIC, myNameFont.UNDERLINE);
            SettingsFile.update("my_separator", mySeparatorFont.color, mySeparatorFont.STYLE, mySeparatorFont.size, mySeparatorFont.BOLD, mySeparatorFont.ITALIC, mySeparatorFont.UNDERLINE);
            SettingsFile.update("my_text", myTextFont.color, myTextFont.STYLE, myTextFont.size, myTextFont.BOLD, myTextFont.ITALIC, myTextFont.UNDERLINE);
            SettingsFile.update("friend_name", friendNameFont.color, friendNameFont.STYLE, friendNameFont.size, friendNameFont.BOLD, friendNameFont.ITALIC, friendNameFont.UNDERLINE);
            SettingsFile.update("friend_separator", friendSeparatorFont.color, friendSeparatorFont.STYLE, friendSeparatorFont.size, friendSeparatorFont.BOLD, friendSeparatorFont.ITALIC, friendSeparatorFont.UNDERLINE);
            SettingsFile.update("friend_text", friendTextFont.color, friendTextFont.STYLE, friendTextFont.size, friendTextFont.BOLD, friendTextFont.ITALIC, friendTextFont.UNDERLINE);

        } catch (SQLException ex) {
            Logger.getLogger(FontStyleFrame.class.getName()).log(Level.SEVERE, null, ex);
            log.warning(myResources.getString("font.log.erro.salvar"));
        }
        //deconectando com o banco de dados
        SettingsFile.desconnect();

        log.info(myResources.getString("font.log.ok.salvar"));

    }//GEN-LAST:event_saveChangesButtonActionPerformed

    /**
     * Mostra a nova fonte configurada
     */
    private void displaySetText() {
        displayFontStyleTextPane.setText("<html>"
                + "<head>"
                + "</head>"
                + myNameFont.setFont("Me", myNameFont.color, myNameFont.STYLE, myNameFont.size, myNameFont.BOLD, myNameFont.ITALIC, myNameFont.UNDERLINE)
                + mySeparatorFont.setFont(" >>> ", mySeparatorFont.color, mySeparatorFont.STYLE, mySeparatorFont.size, mySeparatorFont.BOLD, mySeparatorFont.ITALIC, mySeparatorFont.UNDERLINE)
                + myTextFont.setFont("Hi!!!!!<br>", myTextFont.color, myTextFont.STYLE, myTextFont.size, myTextFont.BOLD, myTextFont.ITALIC, myTextFont.UNDERLINE)
                + friendNameFont.setFont("Friend", friendNameFont.color, friendNameFont.STYLE, friendNameFont.size, friendNameFont.BOLD, friendNameFont.ITALIC, friendNameFont.UNDERLINE)
                + friendSeparatorFont.setFont(" >>> ", friendSeparatorFont.color, friendSeparatorFont.STYLE, friendSeparatorFont.size, friendSeparatorFont.BOLD, friendSeparatorFont.ITALIC, friendSeparatorFont.UNDERLINE)
                + friendTextFont.setFont("Hi dude!!!<br>", friendTextFont.color, friendTextFont.STYLE, friendTextFont.size, friendTextFont.BOLD, friendTextFont.ITALIC, friendTextFont.UNDERLINE)
                + myNameFont.setFont("Me", myNameFont.color, myNameFont.STYLE, myNameFont.size, myNameFont.BOLD, myNameFont.ITALIC, myNameFont.UNDERLINE)
                + mySeparatorFont.setFont(" >>> ", mySeparatorFont.color, mySeparatorFont.STYLE, mySeparatorFont.size, mySeparatorFont.BOLD, mySeparatorFont.ITALIC, mySeparatorFont.UNDERLINE)
                + "<img src=\"file:C:/MyMessenger/Images/emotion_happy.png\" width=\"32\" height=\"32\"></img>"
                + "</html>");
    }

    /**
     * Metodo usado para retornar o indice correspondente ao nome da fonte
     * @param fontName
     * @return 
     */
    private int getFontComboboxIndex(String fontName) {
        if (fontName.equals("Arial")) {
            return 0;
        } else if (fontName.equals("Verdana")) {
            return 1;
        } else if (fontName.equals("Courier New")) {
            return 2;
        } else {
            return 0;
        }

    }
    
    /**
     * Declaração de variáveis
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel boldButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel chooseFontLabel;
    private javax.swing.JLabel chooseYourFontStyleLabel;
    private javax.swing.JLabel colorPickerLabel;
    private javax.swing.JPanel colorPickerPanel;
    private javax.swing.JTextPane displayFontStyleTextPane;
    private javax.swing.JComboBox editingCombobox;
    private javax.swing.JComboBox fontComboBox;
    private javax.swing.JSpinner fontSizeSpinner;
    private javax.swing.JLabel italicButton;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenu optionMenu;
    private javax.swing.JButton saveChangesButton;
    private javax.swing.JMenuItem saveMyDefaultSettingsMenuItem;
    private javax.swing.JMenuItem saveMySettingsMenuItem;
    private javax.swing.JMenu settingsMenu;
    private javax.swing.JLabel styleLabel;
    private javax.swing.JLabel underlineButton;
    // End of variables declaration//GEN-END:variables
    //   private static Logger log = Logger.getLogger(FontStyleFrame.class.getName());

    //  private static ResourceBundle myResources =
    //   ResourceBundle.getBundle("Messages-pt_br", Locale.getDefault());
    //public static void main(String args[]) {
    //    new FontStyleFrame("ChatFontSettings");
    //}
}
